package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.ability;

import com.hannesdorfmann.mosby3.mvi.integrationtest.ResourceTable;
import com.hannesdorfmann.mosby3.mvi.integrationtest.slice.MviFinishInOnCreateAbilitySlice;
import ohos.aafwk.content.Intent;
import com.hannesdorfmann.mosby3.mvi.MviAbility;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.Subject;

public class MviFinishInOnStartAbility extends MviAbility<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView {

    public Subject<Boolean> onDestroyReached  = BehaviorSubject.create();

    @Override
    public LifecycleTestPresenter createPresenter() {
        return new LifecycleTestPresenter();
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_lifecycle);
//        super.setMainRoute(MviFinishInOnCreateAbilitySlice.class.getName());
        terminateAbility(); // finish imeediately is what we would like to test --> App should not crash

    }

    @Override
    protected void onStop() {
        super.onStop();
        onDestroyReached.onNext(true);
        onDestroyReached.onComplete();
    }
}
